package com.lxk.mall.pms.controller.app;

import cn.hutool.core.collection.CollUtil;
import com.lxk.mall.pms.controller.app.vo.AppCommentPageReqVO;
import com.lxk.mall.pms.domain.PmsProductComment;
import com.lxk.mall.pms.service.IPmsProductCommentService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 商品评价
 */
@RestController
@RequestMapping("/product/comment")
@Validated
@RequiredArgsConstructor
public class AppProductCommentController {

    private final IPmsProductCommentService productCommentService;

    /**
     * 商品评价分页
     * @param pageVO
     * @return
     */
    @GetMapping("/page")
    public TableDataInfo<PmsProductComment> getCommentPage(@Valid AppCommentPageReqVO pageVO) {
        // 查询评论分页
        TableDataInfo<PmsProductComment> pageResult = productCommentService.getCommentPage(pageVO, Boolean.TRUE);
        if (CollUtil.isEmpty(pageResult.getRows())) {
            return null;
        }
        // 拼接返回
        pageResult.getRows().forEach(item -> {
            if (Boolean.TRUE.equals(item.getAnonymous())) {
                item.setUserNickname("匿名用户");
            }
        });
        return pageResult;
    }

}
